<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['lang']){
	$_SESSION['show_lang']=$_RQ['lang'];
}
$return['mid']=$_SESSION['uid'];
$return['show_setmobile']=cfc('core')->check_setmobile(1);
$return['show_setmember']=cfc('core')->check_setmember(1);
if($_RQ['op']=='main'){
	if($_RQ['goodsid']){
		$login_burl='jy_xiaofeelian/goods.detail//id='.$_RQ['goodsid'];
		$this->session('login_burl',$login_burl);
	}
	$return=model('jy_weishop/get_order')->getdata($_RQ);
	//返回链接
	$return['forward_url']=base64_encode('jy_xiaofeelian/myhome//fromcreate=1');
	$return['myfee']=$this->model('red')->addmyfee($_SESSION['cityid'],0);
	if($return['member']['paycodetime']<time()-300){
		do{
			$paycode=rand(100000000000,999999999999);
			$check=pdo_getcolumn('jy_xiaofeelian_myfee',array('paycode'=>$paycode,'uniacid'=>$_SESSION['uniacid']),'id');
		}while($check);
		pdo_update('jy_xiaofeelian_myfee',array('paycode'=>$paycode,'paycodetime'=>time()),array('id'=>$return['myfee']['id'],'uniacid'=>$_SESSION['uniacid']));
		$return['myfee']['paycode']=$paycode;
	}
	$return['post']['sendtype'] = 2;
	$return['post']['endprice']=$return['post']['no_dispatch_price'];
	if($return['myfee']['fee']>$return['post']['endprice']){
		$return['post']['di_myfee']=$return['post']['endprice'];
	}else{
		$return['post']['di_myfee']=$return['myfee']['fee'];
	}
	$return['post']['endprice']-=$return['post']['di_myfee'];
	$return['hexiao']['url']=custom_url('jy_xiaofeelian/hexiao//paycode='.$return['myfee']['paycode'],true);
	set_html('title','核销订单');
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$topaytype=$post['topaytype'];
	//整理订单数据
	$new_order=model('jy_weishop/get_order')->new_order($post);
	$new_order['plugin_name']='jy_xiaofeelian';
	$new_order['api_data']['di_myfee']=$post['di_myfee'];
	$order_id=model('jy_weishop/order')->create($new_order);
	$res=array(
		'order_id'=>$order_id,
	);
	exi($res);
}
?>